using System;
using System.Collections.Generic;
using System.Linq;

namespace Servlets.Api
{
	public class ImmutableArray<T> : System.Collections.IEnumerable
	{
		private readonly T[] array;
		
		public ImmutableArray(T[] array) {
			this.array = array;
		}
		
		public ImmutableArray(List<T> collection) : this(collection.ToArray()){}
		public ImmutableArray(IEnumerable<T> collection) : this(new List<T>(collection)){}
		private ImmutableArray() {
			this.array = new T[0];
		}
		public static ImmutableArray<T> EmptyArray() {
			return new ImmutableArray<T>();
		}
		
		public T this[int index] {
			get {
				return array[index];
			}
		}
		
		public int Length{get{return array.Length;}}
		
		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return array.GetEnumerator();
		}
		
		
		
		
		public override bool Equals(object obj)
		{
			return array.Equals(obj);
		}
		
		public override string ToString()
		{
			return array.ToString();
		}
		
		public override int GetHashCode()
		{
			return array.GetHashCode();
		}
	}
}